<?php

	require_once('../inc/fen_fns.php');
	//sec_session_start();
	
	$did = $_GET['did'];
	
	//if (login_check($mysqli, '>', '50') == true) {

?>

	<div id="users"></div>
	<script type="text/javascript">

	var oTable;

	$(document).ready(function() {

	    $(".contentTopArea").hide();
	
	    $('.buttonAdd').click(function(){
	    	$(".contentTopArea").slideToggle(150);
	    	$(".contentTopArea").load("users/add_user_form.php", function(){
	        }); 
	    });
	
	    oTable = $('#example').dataTable( {
			"sPaginationType": "full_numbers",
			"sDom": 'f<"toolbar">Trtlip',
			"oTableTools": {
				"aButtons": [
					"xls"
				]
			}
		} );
	
		$("div.toolbar").html('');

	} );
	
	function showUser(obj) {  
	
		jQuery(document).ready(function($) {
			  $('a[rel*=facebox]').facebox() 
	
			  jQuery.facebox({ ajax: 'reports/users-detailed.php?uid='+obj })
		}) 
	} 
	
	</script>
			<div id="summaryTableBigTopp">
<?php 
					
						$query0 = $_DB->Query("SELECT
											department_name
											from fen_department
											WHERE
											id = '".$did."'");
						$count0 = $_DB->GetResultNumber($query0);
						
						echo $_DB->GetResultValue($query0, "0", "department_name"); 
						
						
						
						
						?> Bölümü Öğretim Üyeleri
			</div>
			<div class="showtableusers">

			<form id="form">
				<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
						<thead>
							<tr>
								<th>Ünvan</th>
								<th>Adı</th>
								<th>Soyadı</th>							
								<th>Fakülte Bölümü</th>
								<th>Makale</th>
								<th>Kitap Bölümü</th>
								<th>Kitap</th>
								<th>Toplam</th>
								<th>İncele</th>
							</tr>
						</thead>
						<tbody>
						
<?php 

						$query = $_DB->Query("SELECT
											fen_members.id as id,
											fen_members.titr as titr,
											fen_members.name as name,
											fen_members.surname as surname,
											fen_members.username as username,
											fen_department.department_name as department_name,
											fen_members.email as email,
											fen_members.access_level as access_level,
											fen_members.status as status
											from fen_members, fen_department
											WHERE
											fen_members.department_id = '".$did."' and fen_members.department_id = fen_department.id
											ORDER BY fen_members.name ASC");
						$count = $_DB->GetResultNumber($query);

						for ($i=0; $i<$count; $i++)
						{
							
							if ($_DB->GetResultValue($query, $i, "status") == '1') {
								$status = "Aktif";
							} else {
								$status = "Pasif";
							}
							
							$id = $_DB->GetResultValue($query, $i, "id");
							
							$query2 = $_DB->Query("SELECT
									date_FORMAT(time , '%d-%m-%Y %H:%i') as logintime 
									FROM fen_logins
									WHERE
									fen_logins.user_id = '$id'
									ORDER BY time DESC");
							$query3 = $_DB->Query("SELECT
									SUM(yayin_tipi = 'Makale') as makalesayisi, 
									SUM(yayin_tipi = 'Kitap Bölümü') as kitapbolumusayisi,
									SUM(yayin_tipi = 'Kitap') as kitapsayisi,
									COUNT(yayin_tipi) as toplam
									FROM fen_publications
									WHERE
									fen_publications.member_id = '$id'");
							
							if ($_DB->GetResultValue($query, $i, "titr") == 'Prof. Dr.') {
								$titr = "<p id=\"hiddentitr\">1</p>Prof. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Doç. Dr.') {
								$titr = "<p id=\"hiddentitr\">2</p>Doç. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Yrd. Doç. Dr.') {
								$titr = "<p id=\"hiddentitr\">3</p>Yrd. Doç. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Öğr. Gör. Dr.') {
								$titr = "<p id=\"hiddentitr\">4</p>Öğr. Gör. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Öğr. Gör.') {
								$titr = "<p id=\"hiddentitr\">5</p>Öğr. Gör.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Uzm.') {
								$titr = "<p id=\"hiddentitr\">6</p>Uzm.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Okutman') {
								$titr = "<p id=\"hiddentitr\">7</p>Okutman";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Arş. Gör.') {
								$titr = "<p id=\"hiddentitr\">8</p>Arş. Gör.";
							}
							
							echo "
								<tr>
									<td>".$titr."</td>
									<td>".$_DB->GetResultValue($query, $i, "name")."</td>
									<td>".$_DB->GetResultValue($query, $i, "surname")."</td>
									<td>".$_DB->GetResultValue($query, $i, "department_name")."</td>
									<td class=\"center\">".$_DB->GetResultValue($query3, "0", "makalesayisi")."</td>
									<td class=\"center\">".$_DB->GetResultValue($query3, "0", "kitapbolumusayisi")."</td>
									<td class=\"center\">".$_DB->GetResultValue($query3, "0", "kitapsayisi")."</td>
									<td class=\"center\">".$_DB->GetResultValue($query3, "0", "toplam")."</td>
									<td class=\"center\"><a class =\"user_detail_but\" onclick=\"showUser('".$_DB->GetResultValue($query, $i, "id")."')\" href=\"#\"><img id=\"editimg\" src=\"images/edit.gif\"></img></a></td>
								</tr>";		
						}

?>
						</tbody>
					</table>
					
				</form>

			</div>
			<br><br>
<?php 
	/*} else {
		header('Location: ./index.php?error=2');
	}*/
?>			